package com.hp.controller;

import com.github.pagehelper.PageInfo;
import com.hp.entity.Dite;
import com.hp.service.DiteService;
import com.hp.util.ResultJson;
import com.hp.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/dite")
public class DiteController {
    @Resource
    DiteService diteService;

    @RequestMapping("/queryAll")
    public ModelAndView queryAll(Dite dite, Integer page, Integer limit, HttpServletResponse response){
        ModelAndView model=new ModelAndView();
        System.out.println(dite+"-------------------dite-------------------");
        List<Dite> list=diteService.queryAll(dite,page,limit);
        PageInfo<Dite> ditePageInfo=new PageInfo<Dite>(list);
        System.out.println(list+"---------------list--------------");
        Utils.returnJson(ResultJson.success(ditePageInfo),response);
        return model;
    }
    @RequestMapping("/insert")
    public String insert(Dite dite, HttpServletResponse resp) throws Exception {
        System.out.println(dite);
        int i = diteService.insert(dite);
        System.out.println(i + "----------222--------");
        Utils.returnJson(ResultJson.success(i), resp);
        return null;
    }
    @RequestMapping("/findId")
    public ModelAndView findId(Integer id, HttpServletRequest req, HttpServletResponse resp) {
        Dite dite = diteService.findId(id);
        System.out.println(dite + "<<<<<<<<<id>>>>>>>>>");
        ModelAndView modelAndView = new ModelAndView();
        Utils.returnJson(ResultJson.success(dite), resp);
        return null;
    }
    @RequestMapping("/update")
    public String update(Dite dite, HttpServletResponse resp) throws Exception {
        int i = diteService.update(dite);
        System.out.println(i + "----------111--------");
        Utils.returnJson(ResultJson.success(i), resp);
        return null;
    }
    @RequestMapping("/del")
    public ModelAndView del(Integer id, HttpServletResponse resp) {
        ModelAndView model = new ModelAndView();
        System.out.println(id);
        int i = diteService.del(id);
        Utils.returnJson(ResultJson.success(i), resp);
        return model;
    }
}
